#include "CDalMinion.h"

#include <iostream>
#include <sstream>

#include "CDalRecord.h"

CDalMinion::CDalMinion()
{

}

CDalMinion::~CDalMinion()
{

}

CDalRecord* CDalMinion::getMinionType()
{
  const char *sql = "SELECT * FROM ref_minion_type";
  return selectSql("londb", sql);
}

bool CDalMinion::insertMinion(const char *name,
                              int hp,
                              int mp,
                              int attack,
                              int defense,
                              int magic_attack,
                              int magic_defense,
                              int speed,
                              int range,
                              int movement,
                              int level,
                              int type,
                              int owner)
{
  // construct query
  std::ostringstream sout (std::ostringstream::out);
  sout << "INSERT INTO minion (minion_name, hp, mp, attack, defense, ";
  sout << "magic_attack, magic_defense, speed, range, movement, level, ";
  sout << "minion_type_id, owner_id) VALUES (";
  sout << "'" << escape(name, '\'') << "', ";
  sout << hp << ", ";
  sout << mp << ", ";
  sout << attack << ", ";
  sout << defense << ", ";
  sout << magic_attack << ", ";
  sout << magic_defense << ", ";
  sout << speed << ", ";
  sout << range << ", ";
  sout << movement << ", ";
  sout << level << ", ";
  sout << type << ", ";
  sout << owner << ");";

  std::string sql = sout.str();

  // execute query
  return insertSql("lonserverdb", sql.c_str());
}

bool CDalMinion::removeMinion(int minion_id)
{
 // construct query
  std::ostringstream sout (std::ostringstream::out);
  sout << "DELETE FROM minion WHERE minion_id = " << minion_id;
  std::string sql = sout.str();

  return insertSql("lonserverdb", sql.c_str());
}
